package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.PageInfo;
import com.yyb.common.Result;
import com.yyb.domain.SysNotice;
import com.yyb.dto.SysNoticeAddDTO;
import com.yyb.dto.SysNoticeQueryDTO;
import com.yyb.dto.SysNoticeUpdateDTO;
import com.yyb.enums.BusinessType;
import com.yyb.service.SysNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 描述: [通知公告相关的API]
 * 
 * 
 */
@RestController
@Tag(name = "通知公告相关的API")
@RequestMapping("sysNotice")
public class SysNoticeController extends BaseController{

    @Resource
    private SysNoticeService sysNoticeService;
    /**
     * 分页查询通知公告
     * POST http://127.0.0.1:8080/sysNotice/getByPage
     * 接口ID：148742213
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742213
     */
    @PostMapping("getByPage")
    @Operation(summary = "分页查询通知公告")
    @AppPermission("system:notice:query")
    public Result<PageInfo<SysNotice, SysNoticeQueryDTO>> getByPage(@RequestBody PageInfo<SysNotice, SysNoticeQueryDTO> pageInfo) {
        PageInfo<SysNotice, SysNoticeQueryDTO> info = this.sysNoticeService.getByPage(pageInfo);
        return new Result<>(info);
    }

    /**
     * 添加通知公告
     * POST http://127.0.0.1:8080/sysNotice/save
     * 接口ID：148742214
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742214
     */
    @PostMapping("save")
    @Operation(summary = "添加通知公告")
    @AppPermission("system:notice:add")
    @Log(title = "通知公告-添加",businessType = BusinessType.INSERT)
    public Result<?> save(@RequestBody @Validated SysNoticeAddDTO sysNoticeAddDTO) {
        int row = this.sysNoticeService.insert(sysNoticeAddDTO);
        return this.toAjax(row > 0);
    }


    /**
     * 修改通知公告
     * PUT http://127.0.0.1:8080/sysNotice/update
     * 接口ID：148742215
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742215
     */
    @PutMapping("update")
    @AppPermission("system:notice:update")
    @Log(title = "通知公告-修改",businessType = BusinessType.UPDATE)
    @Operation(summary = "修改通知公告")
    public Result<?> update(@RequestBody @Validated SysNoticeUpdateDTO sysNoticeUpdateDTO) {
        int row = this.sysNoticeService.updateByPrimaryKey(sysNoticeUpdateDTO);
        return this.toAjax(row > 0);
    }

    /**
     * 根据ID查询通知公告
     * GET http://127.0.0.1:8080/sysNotice/get/{noticeId}
     * 接口ID：148742217
     * 接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742217
     */
    @GetMapping("get/{noticeId}")
    @AppPermission("system:notice:query")
    @Operation(summary = "根据ID查询通知公告")
    public Result<SysNotice> get(@PathVariable Long noticeId) {
        SysNotice sysNotice = this.sysNoticeService.selectByPrimaryKey(noticeId);
        return new Result<>(sysNotice);
    }

    /**
     *删除通知公告
     *   DELETE http://127.0.0.1:8080/sysNotice/delete/{noticeId}
     *   接口ID：148742216
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742216
     */
    @DeleteMapping("delete/{noticeId}")
    @AppPermission("system:notice:remove")
    @Log(title = "通知公告-删除",businessType = BusinessType.DELETE)
    @Operation(summary = "根据ID删除通知公告")
    public Result<?> delete(@PathVariable Long noticeId) {
        int row = this.sysNoticeService.deleteByPrimaryKey(noticeId);
        return this.toAjax(row>0);
    }

}
